import 
{ 
    ref ,
    reactive, 
    toRefs,
    onMounted ,
    onUnmounted,
    provide
} from 'vue'

import appInit from '@/hook/appInit'
import nowDate from '@/hook/nowDate'
import menu from '@/hook/menu'
import window from '@/hook/window'
import files from '@/hook/files'

import DesktopMenu from '@/components/DesktopMenu'
import IconMenu from '@/components/IconMenu'
import CalendarMenu from '@/components/CalendarMenu'
import LeftMenu from '@/components/LeftMenu'
import HomeMenu from '@/components/HomeMenu'
import ControlMenu from '@/components/ControlMenu'
import FileExplorer from '@/components/FileExplorer'
import Edge from '@/components/Edge'
import CommonWindow from '@/components/CommonWindow'
import AppIcon from '@/components/AppIcon'
import BottomNav from '@/components/BottomNav'


export default {
    name:'mainPage',
    components:
    { 
        IconMenu,
        DesktopMenu,ControlMenu,
        CalendarMenu,LeftMenu,HomeMenu,
        FileExplorer,Edge,CommonWindow,AppIcon,BottomNav
    },
    emits:['refresh'],
    setup(props,context) {
        let timer = null;

        onMounted(() => {
            document.addEventListener('selectstart',function(e){
                e.preventDefault();
            })
           
            let wallpaper = document.querySelector('.wallpaper')
            const getRandom = ()=>{
                return Math.round(Math.random())+1
            }
            let pic1 = require('@/assets/wallpaper/img1.jpg')
            let pic2 = require('@/assets/wallpaper/img0.jpg')
            let arr = [pic1,pic2]
            timer = setInterval(() => {
                wallpaper.style.backgroundImage = `url(${arr[getRandom()-1]})`
            }, 15000);
        })
      
        onUnmounted(() => {
            document.removeEventListener('selectstart',function(e){
                e.preventDefault();
            })
           
            clearInterval(timer)
        })

        return {
            ...toRefs(window()),
            ...toRefs(nowDate()),
            ...appInit(),
            ...toRefs(menu()),

        }
    }
}